package com.jk.rabbitmqsend.controller;

import com.alibaba.fastjson.JSON;
import com.jk.rabbitmqsend.bean.OrderForm;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.UUID;

@RestController
public class SendController {

    @Resource
    private AmqpTemplate  amqpTemplate;

    @RequestMapping("saveOrder")
    public  void  saveOrder(){
        OrderForm orderForm = new OrderForm();
        UUID uuid = UUID.randomUUID();
        System.out.println(uuid);
        orderForm.setOrderId(1);
        orderForm.setOrderName("奔驰G500");
        orderForm.setOrderNum(uuid+"");
        orderForm.setOrderPrice(4600000.00);
        orderForm.setCreateTime(new Date());

        String OrderJson = JSON.toJSONString(orderForm);

        amqpTemplate.convertAndSend("1807B-hly",OrderJson);

    }
}
